Conversation
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
|
|
||
| OAuthResponse response; | ||
| try { | ||
| response = new ObjectMapper().readValue(rawResponse.getBody(), OAuthResponse.class); |
There was a problem hiding this comment.
This ObjectMapper is created for each token request. Can we define this as a static final field for this class? Is this readvalue() method thread safe?
There was a problem hiding this comment.
On the other hand, calls to this method are not frequent, and soon will be done async.
Specially if readvalue() is not thread safe, I would not bother.
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Outdated
Show resolved
Hide resolved
| private String audience; | ||
|
|
||
| /** | ||
| * Validates that a value is non-empty and non-null for required fields. |
There was a problem hiding this comment.
I think this comment is not correct. We don't have a non-empty check for all the objects. It is only for the Strings. So, we can clarify it here.
| if (testCase.expectError) { | ||
| if (testCase.statusCode == 0) { | ||
| when(mockHttpClient.execute(any())).thenThrow(new IOException("Network error")); | ||
| } else { | ||
| when(mockHttpClient.execute(any())) | ||
| .thenReturn( | ||
| new Response( | ||
| testCase.responseBody, testCase.statusCode, "Bad Request", new URL(TEST_HOST))); | ||
| } | ||
| } else { | ||
| when(mockHttpClient.execute(any())) | ||
| .thenReturn(new Response(testCase.responseBody, new URL(TEST_HOST))); | ||
| } |
There was a problem hiding this comment.
Can we include the mock HTTP client's request and response in the test case itself?
renaudhartert-db
left a comment
There was a problem hiding this comment.
LGTM overall, deferring final approval to @parthban-db and @hectorcast-db.
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/oauth/DatabricksOAuthTokenSource.java
Show resolved
Hide resolved
| OpenIDConnectEndpoints endpoints, | ||
| IDTokenSource idTokenSource, | ||
| HttpClient httpClient) { | ||
| validate(clientId, "ClientID"); |
There was a problem hiding this comment.
To be consistent, we need to validate this on Token(), not when creating the TokenSource.
In other providers, we only check if the fields are set when calling an endpoint/need a token. If we check it earlier, the client construction may fail.
| @Override | ||
| public Token getToken() { | ||
| // Validate all required parameters | ||
| if (!validate(clientId, "ClientID") |
There was a problem hiding this comment.
It may be more helpful to the user if they see which parameter is missing. Shall we hvae validate itself throw the exception with the field name in it?
Also note that validate takes the field name, but it does not use it.
| * required fields cause getToken() to throw IllegalArgumentException. | ||
| */ | ||
| @Test | ||
| void testParameterValidation() { |
There was a problem hiding this comment.
Can this be written as a parameterized test?
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
What changes are proposed in this pull request?
How is this tested?
The implementation is tested through unit tests that:
NO_CHANGELOG=true